home *** CD-ROM | disk | FTP | other *** search
- From theseas!fs.Princeton.EDU!cek Sat, 8 May 93 01:34:11 EET
- Received: by kriton.UUCP (V1.16/Amiga)
- id AA00000; Sat, 8 May 93 01:34:11 EET
- Received: by theseas.ntua.gr with UUCP; Fri, 7 May 93 14:46:34 +0300
- Received: from mcsun.EU.net by pythia.ics.forth.gr via ITEnet with SMTP;
- id AA05390 (5.65c/FORTH-ICS-3.0-MHS-7.0); Fri, 7 May 1993 14:42:23 +0300
- Received: by mcsun.EU.net via EUnet
- id AA25040 (5.65b/CWI-2.217); Fri, 7 May 1993 13:37:20 +0200
- Received: from Princeton.EDU by relay1.UU.NET with SMTP
- (5.61/UUNET-internet-primary) id AB16762; Fri, 7 May 93 07:36:31 -0400
- Received: from fs.Princeton.EDU by Princeton.EDU (5.65b/2.96/princeton)
- id AA05481; Fri, 7 May 93 07:36:25 -0400
- Received: by fs.Princeton.EDU (4.1/1.105)
- id AA25196; Fri, 7 May 93 07:36:24 EDT
- Received: from pobox.cscs.ch by fs.Princeton.EDU (4.1/1.105)
- id AA25110; Fri, 7 May 93 07:35:39 EDT
- Received: from staff-fddi.cscs.ch by pobox.cscs.ch with SMTP inbound
- id <5598-0@pobox.cscs.ch>; Fri, 7 May 1993 13:35:28 +0200
- Received: from localhost by staff-ether id AA28928; Fri, 7 May 93 13:35:23 +0200
- Message-Id: <9305071135.AA28928@staff-ether>
- Date: Fri, 07 May 93 13:35:22 +0200
- Errors-To: Princeton.EDU!cek
- Remailed-Date: Fri May 7 07:35:43 EDT 1993
- From: cscs.ch!athurn
- To: cs.Princeton.EDU!rayshade-users
- Subject: Portable Heighfields (patch)
-
-
- Hello Rayshade Users:
-
- I finally got around to solving the heightfield portability problem.
- The following patch is to be applied to libray/libobj/hf.c. After
- recompilation (see notes below), Rayshade and Inetray expect the
- heightfield data files to be XDR files (eXternal Data Representation -
- the stuff SUN uses for RPC and therefore NFS). Compared to a binary
- file, there is a 40 byte overhead but the XDR file is completely
- portable.
-
- Just patching hf.c and recompiling doesn't change anything. To compile
- the new stuff -DXDRHF has to be added to the ccflags in config.sh (and
- then Reconfigure has to be run). On some machines (e.g. SGI)
- the library containing the xdr-routines have to be added (in the case of
- of SGI they reside in libsun.a). Furthermore the compiler has to be
- instructed to handle non-ansi c since the SUN header files are not (yet)
- ansi clean (on the SGI -cckr has to be added to the ccflags).
-
- The patch has been tested on SGIs and on a DECstation (which has
- different byte ordering).
-
- Following the patch is a short c program (hf2xhf) which converts
- old-style binary hf files to the new xhf (XDR heightfield) files.
-
- Cheers
- - ant
-
- ============= patch.hf.c ================================================
- 25a26,30
- > #ifdef XDRHF
- > #include <rpc/rpc.h>
- > #include <fcntl.h>
- > #define MAXSIZE ((u_int)1000000)
- > #endif
- 48a54,61
- > #ifdef XDRHF
- > readbuf(fdp,buf,count)
- > int *fdp; void *buf; u_int count;
- > {
- > return read(*fdp,buf,count);
- > }
- > #endif
- >
- 53,56c66,76
- < Hf *hf;
- < FILE *fp;
- < float val, *maxptr, *minptr;
- < int i, j;
- ---
- > Hf *hf;
- > float val, *maxptr, *minptr;
- > int i, j;
- > #ifdef XDRHF
- > static int fp;
- > u_int sqSize;
- > XDR xdrs;
- > float *buf;
- > #else
- > FILE *fp;
- > #endif
- 57a78,80
- > #ifdef XDRHF
- > if ((fp = open(filename,O_RDONLY)) < 0) {
- > #else
- 59a83
- > #endif
- 76a101,105
- > #ifdef XDRHF
- > xdrrec_create(&xdrs,0,0,&fp,readbuf,NULL);
- > xdrs.x_op = XDR_DECODE;
- > if (!xdrrec_skiprecord(&xdrs)) {
- > #else
- 77a107
- > #endif
- 81a112,120
- > #ifdef XDRHF
- > buf = NULL;
- > if (!xdr_array(&xdrs,&buf,&sqSize,MAXSIZE,
- > (u_int)sizeof(float),xdr_float)) {
- > RLerror(RL_ABORT, "xdr_array() failed.\n");
- > return (Hf *)NULL;
- > }
- > hf->size = (int)sqrt((double)sqSize);
- > #endif
- 83a123,125
- > #ifdef XDRHF
- > hf->data[i] = &buf[i*hf->size];
- > #else
- 84a127
- > #endif
- 87a131
- > #ifndef XDRHF
- 92a137
- > #endif
- 108a154,156
- > #ifdef XDRHF
- > (void)close(fp);
- > #else
- 109a158
- > #endif
- ============= end of patch.hf.c =====================================
-
- /*======================================================================
- H F 2 X H F . C
- doc: Fri Apr 30 11:27:46 1993
- dlm: Fri May 7 11:22:17 1993
- (c) 1993 ant@bernina.ethz.ch
- uE-Info: 58 40 T 0 0 72 2 2 4 ofnI
- ======================================================================*/
-
- #include <stdio.h>
- #include <fcntl.h>
- #include <rpc/rpc.h>
-
- #define int32 int
- #define float32 float
-
- #define USE_DEFAULT 0
-
- static int ofd; /* could also be passed */
-
- main(ac,av)
- int ac; char *av[];
- {
- int ifd,i,writebuf();
- int32 size;
- u_int sqSize;
- float32 val,*array;
- XDR xdrs;
-
- if (ac != 3) {
- fprintf(stderr,"Usage: %s <infile> <outfile>\n",av[0]);
- exit(1);
- }
-
- if ((ifd = open(av[1],O_RDONLY)) < 0) {
- perror("open infile");
- exit(1);
- }
- read(ifd,&size,4);
- printf("HF size = %d\n",size);
- sqSize = size*size;
- array = (float32 *)malloc(sqSize*sizeof(float32));
- if (array == NULL) {
- fprintf(stderr,"malloc() failed!\n");
- exit(1);
- }
- for (i=0; i<sqSize; i++) {
- read(ifd,&val,4);
- array[i] = (float32)val;
- }
- close(ifd);
-
- if ((ofd = creat(av[2],0666)) < 0) {
- perror("open outfile");
- exit(1);
- }
- xdrrec_create(&xdrs,USE_DEFAULT,USE_DEFAULT,NULL,NULL,writebuf);
- xdrs.x_op = XDR_ENCODE;
- if (!xdr_array(&xdrs,&array,&sqSize,sqSize,
- (u_int)sizeof(float32),xdr_float)) {
- fprintf(stderr,"xdr_array() failed!\n");
- exit(1);
- }
- if (!xdrrec_endofrecord(&xdrs,TRUE)) {
- fprintf(stderr,"xdr_endofrecord() failed!\n");
- exit(1);
- }
- close(ofd);
-
- exit(0);
- }
-
- writebuf(dummyParam,buf,count) /* write stub */
- char *dummyParam,*buf; int count;
- {
- return write(ofd,buf,count);
- }
-
-
- ----------
- Administrivia: rayshade-request@cs.princeton.edu
- Mailing list: rayshade-users@cs.princeton.edu
-
-